package com.white.shm.entity;


import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import lombok.Data;

/**
 *
 *
 * @title BaseEntity.java
 * @since 2019/12/13 00:10
 * @author White
 * @version 1.0
 */
@Data
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
    /**
     * The constant serialVersionUID.
     */
    private static final long serialVersionUID = -5010345906752653058L;

    // This will disable insert batching - AVOID IT! 会失效批处理
    // @GeneratedValue(strategy = GenerationType.IDENTITY)

    // This will work, but better use the below solution 性能不佳
    // @GeneratedValue(strategy = GenerationType.AUTO)

    // This will allow insert batching and optimizes the identifiers
    // generation via the hi/lo algorithm
    /**
     * The Id.
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "idGenerator")
    @GenericGenerator(name = "idGenerator",
            strategy = "org.hibernate.id.enhanced.SequenceStyleGenerator",
            parameters = {
                    @Parameter(name = "sequence_name", value = "db_secondhandmarket.shm_id_seq"),
                    @Parameter(name = "initial_value", value = "1"),
                    @Parameter(name = "increment_size", value = "1"),
                    @Parameter(name = "optimizer", value = "hilo")
            })
    @Column(name = "id")
    private int id;

    /**
     * The Create by.
     */
    @Column(name = "create_by", updatable = false)
    private String createBy;
    /**
     * The Create time.
     */
    @Column(name = "create_time", updatable = false)
    private Date createTime;
    /**
     * The Update by.
     */
    @Column(name = "update_by")
    private String updateBy;
    /**
     * The Update time.
     */
    @Column(name = "update_time")
    private Date updateTime;

}
